import request from '@/utils/request'
import type { AddPatient, User } from '@/types/user'
import type { AxiosResponse } from 'axios'

export const loginAPI = (mobile: string, password: string): Promise<AxiosResponse<User, any>> => {
  return request({
    url: '/login/password',
    method: 'post',
    data: { mobile, password }
  })
}

export const sendCodeAPI = (mobile: string, type = 'login') => {
  return request({
    url: '/code',
    params: { mobile, type }
  })
}

export const loginByCodeAPI = (mobile: string, code: string): Promise<AxiosResponse<User, any>> => {
  return request({
    url: '/login',
    method: 'post',
    data: { mobile, code }
  })
}

// 获取个人信息
export const getUserInfoAPI = () => {
  return request({
    url: '/patient/myUser'
  })
}

/** 获取患者列表 */
export const getPatientListAPI = () => {
  return request({ url: '/patient/mylist' })
}

/** 添加患者 */
export const addPatientAPI = (patient: AddPatient) => {
  return request({ url: '/patient/add', method: 'POST', data: patient })
}

/** 编辑患者 */
export const editPatientAPI = (patient: AddPatient) => {
  return request({ url: '/patient/update', method: 'PUT', data: patient })
}
export const delPatientAPI = (id: string) => {
  return request({ url: `/patient/del/${id}`, method: 'DELETE' })
}
